﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibHuman;

namespace Human
{
	/// <summary>
	/// Summary description for bieu_tinhhinhCCVCtheoquy.
	/// </summary>
	public class bieu_tinhhinhCCVCtheoquy : System.Windows.Forms.Form
	{
		private AccessData mDB=new AccessData();
		private ExportToExcel p=new ExportToExcel();
		private DataSet dsxml =new DataSet();
		private frmReport  rpt;
        Language lan = new Language();
        string ngay = "",user="",s_mmyy="",s_bophan="",user_dn="";
		private System.Windows.Forms.Button btnXem;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.RadioButton radMH;
		private System.Windows.Forms.RadioButton radMI;
		private System.Windows.Forms.RadioButton radExcel;
		private System.Windows.Forms.Button btnThoat;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.NumericUpDown nudNam;
        private System.Windows.Forms.NumericUpDown nudQuy;
		private System.ComponentModel.Container components = null;

		public bieu_tinhhinhCCVCtheoquy(string s_makp,string s_userdn)
		{
			InitializeComponent();
            lan.Read_Language_to_Xml(this.Name.ToString(), this);
            lan.Changelanguage_to_English(this.Name.ToString(), this);
            s_bophan = s_makp;
            user_dn = s_userdn;
		}

		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
        string tungay = "", denngay = "";

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(bieu_tinhhinhCCVCtheoquy));
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.radMH = new System.Windows.Forms.RadioButton();
            this.radMI = new System.Windows.Forms.RadioButton();
            this.radExcel = new System.Windows.Forms.RadioButton();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.nudNam = new System.Windows.Forms.NumericUpDown();
            this.nudQuy = new System.Windows.Forms.NumericUpDown();
            this.btnXem = new System.Windows.Forms.Button();
            this.btnThoat = new System.Windows.Forms.Button();
            this.groupBox1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.nudNam)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.nudQuy)).BeginInit();
            this.SuspendLayout();
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.radMH);
            this.groupBox1.Controls.Add(this.radMI);
            this.groupBox1.Controls.Add(this.radExcel);
            this.groupBox1.ForeColor = System.Drawing.Color.DarkBlue;
            this.groupBox1.Location = new System.Drawing.Point(12, 50);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(208, 48);
            this.groupBox1.TabIndex = 2;
            this.groupBox1.TabStop = false;
            // 
            // radMH
            // 
            this.radMH.Checked = true;
            this.radMH.Location = new System.Drawing.Point(6, 16);
            this.radMH.Name = "radMH";
            this.radMH.Size = new System.Drawing.Size(69, 24);
            this.radMH.TabIndex = 0;
            this.radMH.TabStop = true;
            this.radMH.Text = "Màn hình";
            this.radMH.KeyDown += new System.Windows.Forms.KeyEventHandler(this.radMH_KeyDown);
            // 
            // radMI
            // 
            this.radMI.Location = new System.Drawing.Point(82, 16);
            this.radMI.Name = "radMI";
            this.radMI.Size = new System.Drawing.Size(56, 24);
            this.radMI.TabIndex = 1;
            this.radMI.Text = "Máy In";
            this.radMI.KeyDown += new System.Windows.Forms.KeyEventHandler(this.radMI_KeyDown);
            // 
            // radExcel
            // 
            this.radExcel.Location = new System.Drawing.Point(144, 16);
            this.radExcel.Name = "radExcel";
            this.radExcel.Size = new System.Drawing.Size(52, 24);
            this.radExcel.TabIndex = 1;
            this.radExcel.Text = "Excel";
            this.radExcel.KeyDown += new System.Windows.Forms.KeyEventHandler(this.radExcel_KeyDown);
            // 
            // label1
            // 
            this.label1.ForeColor = System.Drawing.Color.DarkBlue;
            this.label1.Location = new System.Drawing.Point(23, 28);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(26, 13);
            this.label1.TabIndex = 22;
            this.label1.Text = "Qúy";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label2
            // 
            this.label2.ForeColor = System.Drawing.Color.DarkBlue;
            this.label2.Location = new System.Drawing.Point(118, 28);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(29, 13);
            this.label2.TabIndex = 22;
            this.label2.Text = "Năm";
            this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // nudNam
            // 
            this.nudNam.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.nudNam.ForeColor = System.Drawing.Color.Red;
            this.nudNam.Location = new System.Drawing.Point(152, 24);
            this.nudNam.Maximum = new decimal(new int[] {
            2012,
            0,
            0,
            0});
            this.nudNam.Minimum = new decimal(new int[] {
            2000,
            0,
            0,
            0});
            this.nudNam.Name = "nudNam";
            this.nudNam.Size = new System.Drawing.Size(56, 20);
            this.nudNam.TabIndex = 1;
            this.nudNam.Value = new decimal(new int[] {
            2000,
            0,
            0,
            0});
            this.nudNam.KeyDown += new System.Windows.Forms.KeyEventHandler(this.nudNam_KeyDown);
            // 
            // nudQuy
            // 
            this.nudQuy.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.nudQuy.ForeColor = System.Drawing.Color.Red;
            this.nudQuy.Location = new System.Drawing.Point(54, 24);
            this.nudQuy.Maximum = new decimal(new int[] {
            4,
            0,
            0,
            0});
            this.nudQuy.Minimum = new decimal(new int[] {
            1,
            0,
            0,
            0});
            this.nudQuy.Name = "nudQuy";
            this.nudQuy.Size = new System.Drawing.Size(46, 20);
            this.nudQuy.TabIndex = 0;
            this.nudQuy.Value = new decimal(new int[] {
            1,
            0,
            0,
            0});
            this.nudQuy.KeyDown += new System.Windows.Forms.KeyEventHandler(this.nudQuy_KeyDown);
            // 
            // btnXem
            // 
            this.btnXem.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnXem.ForeColor = System.Drawing.Color.DarkBlue;
            this.btnXem.Image = global::Human.Properties.Resources.t_search;
            this.btnXem.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btnXem.Location = new System.Drawing.Point(51, 111);
            this.btnXem.Name = "btnXem";
            this.btnXem.Size = new System.Drawing.Size(60, 28);
            this.btnXem.TabIndex = 3;
            this.btnXem.Text = "X&em";
            this.btnXem.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btnXem.Click += new System.EventHandler(this.btnXem_Click);
            // 
            // btnThoat
            // 
            this.btnThoat.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnThoat.ForeColor = System.Drawing.Color.DarkBlue;
            this.btnThoat.Image = global::Human.Properties.Resources.close_r;
            this.btnThoat.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btnThoat.Location = new System.Drawing.Point(117, 111);
            this.btnThoat.Name = "btnThoat";
            this.btnThoat.Size = new System.Drawing.Size(60, 28);
            this.btnThoat.TabIndex = 4;
            this.btnThoat.Text = "&Thoát";
            this.btnThoat.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btnThoat.Click += new System.EventHandler(this.btnThoat_Click);
            // 
            // bieu_tinhhinhCCVCtheoquy
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(237, 157);
            this.Controls.Add(this.nudNam);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.btnXem);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.btnThoat);
            this.Controls.Add(this.nudQuy);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "bieu_tinhhinhCCVCtheoquy";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Tình hình CBCC theo qúy";
            this.Load += new System.EventHandler(this.bieu_tinhhinhCCVCtheoquy_Load);
            this.groupBox1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.nudNam)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.nudQuy)).EndInit();
            this.ResumeLayout(false);

		}
		#endregion

		private void bieu_tinhhinhCCVCtheoquy_Load(object sender, System.EventArgs e)
		{
			int i=int.Parse(DateTime.Now.Month.ToString());
			if(i==1||i==2||i==3)
				nudQuy.Value=1;
			else if(i==4||i==5||i==6)
				nudQuy.Value=2;
			else if(i==7||i==8||i==9)
				nudQuy.Value=3;
			else
				nudQuy.Value=4;
			nudNam.Value=int.Parse(DateTime.Now.Year.ToString());
		}
        public void getngay()
        {
            if (nudNam.Text.Trim() != "")
            {
                switch (nudQuy.Text)
                {
                    case "1": tungay = nudNam.Text.Trim() + "-01-01";
                        denngay = nudNam.Text.Trim() + "-03-31";                        
                        break;
                    case "2": tungay = nudNam.Text.Trim() + "-03-31";
                        denngay = nudNam.Text.Trim() + "-06-30";                       
                        break;
                    case "3": tungay = nudNam.Text.Trim() + "-06-30";                     
                        denngay = nudNam.Text.Trim() + "-09-30";                        
                        break;
                    case "4": tungay = nudNam.Text.Trim() + "-09-30";                       
                        denngay = nudNam.Text.Trim() + "-12-31";                        
                        break;
                    default: tungay = nudNam.Text.Trim() + "-01-01";
                        denngay = nudNam.Text.Trim() + "-03-31";                       
                        break;
                }
            }
            s_mmyy =  denngay.Substring(5, 2)+denngay.Substring(2, 2) ;
        }

 		private void print(int j)
		{
			try
			{
                getngay();
                user = mDB.user;
				int i=int.Parse(nudQuy.Value.ToString());
				int nam=int.Parse(nudNam.Value.ToString());							
				int ss=i*3;
				string s="28/"+ss.ToString().PadLeft(2,'0').ToString()+"/"+nam.ToString(),sql="";

                sql = " SELECT '" + ss.ToString().PadLeft(2, '0').ToString() + "' as thang,'" + nam.ToString() + "' as nam,bp.tenbp,";
                sql += " case when substr(trim(bp.mabsoft),1,1)='P' then 'I. Các phòng' ";
                sql += " when substr(trim(bp.mabsoft),1,1)='L' then 'II. Khoa lâm sàng' ";
                sql += " when substr(trim(bp.mabsoft),1,1)='C' then 'III. Cận lâm sàng' ";
                sql += " when substr(trim(bp.mabsoft),1,1)='D' then 'IV. Y tế dự phòng'";
                sql += " when substr(trim(bp.mabsoft),1,1)='X' then 'V. Y tế xã'";
                sql += " when substr(trim(bp.mabsoft),1,1)='K'  then 'VI. Bộ phận khác' end as label,";
                sql += " count(l.manv) as tongso,";
                sql += " (sum(case when l.phai<>'Nam'  then 1 else 0 end)) as tongnu,";
                sql += " sum(case when l.mahocham in ('2','3')  then 1 else 0 end) as GS,";
                sql += " sum(case when l.td_nnghiep in ('01') and l.mahocham not in('2','3')  then 1 else 0 end) as TS,";
                sql += " sum(case when l.td_nnghiep in ('02')  then 1 else 0 end) as ThS,";
                sql += " sum(case when l.td_nnghiep ='08'  and (l.mahocham not in ('2','3') or l.mahocham ='')  then 1 else 0 end ) as CKII,";
                sql += " sum(case when l.td_nnghiep='07' and (l.mahocham not in ('2','3') or l.mahocham ='')  then 1 else 0 end) as CKI,";
                sql += " sum(case when dt.manhom in ('01') and bc.mabc in ('DH') then 1 else 0 end) as BS,";
                sql += " sum(case when dt.manhom in ('02') and bc.mabc in ('DH')  then 1 else 0 end) as DSDH,";
                sql += " sum(case when dt.manhom in ('06') and bc.mabc in ('DH')  then 1 else 0 end) as YTDH,";
                sql += " sum(case when dt.manhom not in ('01','02','06') and bc.mabc in ('DH')  then 1 else 0 end) as DHkhac,";
                sql += " sum(case when bc.mabc in ('CD')  then 1 else 0 end) as CDang,";
                sql += " sum(case when dt.manhom in ('07') and bc.mabc in ('TH') then 1 else 0 end) as YSTH,";
                sql += " sum(case when dt.manhom in ('04') and bc.mabc in ('TH') then 1 else 0 end) as KTV,";
                sql += " sum(case when dt.manhom in ('02') and bc.mabc in ('TH') then 1 else 0 end) as DSTH,";
                sql += " sum(case when dt.manhom in ('06') and bc.mabc in ('TH') then 1 else 0 end) as YTTH,";
                sql += " sum(case when dt.manhom in ('08') and bc.mabc in ('TH') then 1 else 0 end) as NHSTH,";
                sql += " sum(case when dt.manhom not in ('02','04','06','07','08') and bc.mabc in ('TH') then 1 else 0 end) as THkhac,";
                sql += " sum(case when dt.manhom in ('06')  and bc.mabc in ('SH') then 1 else 0 end) as YTSH,";
                sql += " sum(case when dt.manhom in ('08') and bc.mabc in ('SH') then 1 else 0 end) as NHSSH,";
                sql += " sum(case when dt.manhom in ('03') and bc.mabc in ('SH') then 1 else 0 end) as Dta,";
                sql += " 0 as CBkhac,";
                sql += " sum(case when dt.manhom in ('10') then 1 else 0 end) as luongy";
               
                sql += " ,sum(case when (mh.nhombc=2) then 1 else 0 end) as Tquy,";
                sql += " sum(case when (mh.nhombc=3 or mh.nhombc=4) then 1 else 0 end) as Nquy,";

                sql += " sum(case when l.mahocham in ('2','3') and l.phai<>'Nam'  then 1 else 0 end) as nuGS,";
                sql += " sum(case when l.td_nnghiep in ('01') and l.phai<>'Nam' then 1 else 0 end) as nuTS,";
                sql += " sum(case when l.td_nnghiep in ('02') and l.phai<>'Nam' then 1 else 0 end) as nuThS,";
                sql += " sum(case when l.td_nnghiep ='08'  and (l.mahocham not in ('2','3') or l.mahocham ='') and l.phai<>'Nam' then 1 else 0 end ) as nuCKII,";
                sql += " sum(case when l.td_nnghiep='07' and (l.mahocham not in ('2','3') or l.mahocham ='') and l.phai<>'Nam' then 1 else 0 end) as nuCKI,";
                sql += " sum(case when dt.manhom in ('01') and bc.mabc in ('DH') and l.phai<>'Nam' then 1 else 0 end) as nuBS,";
                sql += " sum(case when dt.manhom in ('02') and bc.mabc in ('DH') and l.phai<>'Nam' then 1 else 0 end) as nuDSDH,";
                sql += " sum(case when dt.manhom in ('06') and bc.mabc in ('DH') and l.phai<>'Nam' then 1 else 0 end) as nuYTDH,";
                sql += " sum(case when dt.manhom not in ('01','02','06') and bc.mabc in ('DH') and l.phai<>'Nam' then 1 else 0 end) as nuDHkhac,";
                sql += " sum(case when bc.mabc in ('CD') and l.phai<>'Nam'  then 1 else 0 end) as nuCDang,";
                sql += " sum(case when dt.manhom in ('07') and bc.mabc in ('TH') and l.phai<>'Nam' then 1 else 0 end) as nuYSTH,";
                sql += " sum(case when dt.manhom in ('04') and bc.mabc in ('TH') and l.phai<>'Nam' then 1 else 0 end) as nuKTV,";
                sql += " sum(case when dt.manhom in ('02') and bc.mabc in ('TH')and l.phai<>'Nam' then 1 else 0 end) as nuDSTH,";
                sql += " sum(case when dt.manhom in ('06') and bc.mabc in ('TH') and l.phai<>'Nam' then 1 else 0 end) as nuYTTH,";
                sql += " sum(case when dt.manhom in ('08') and bc.mabc in ('TH') and l.phai<>'Nam' then 1 else 0 end) as nuNHSTH,";
                sql += " sum(case when dt.manhom not in ('02','04','06','07','08') and bc.mabc in ('TH') and l.phai<>'Nam' then 1 else 0 end) as nuTHkhac,";
                sql += " sum(case when dt.manhom in ('06')  and bc.mabc in ('SH') and l.phai<>'Nam' then 1 else 0 end) as nuYTSH,";
                sql += " sum(case when dt.manhom in ('08') and bc.mabc in ('SH') and l.phai<>'Nam' then 1 else 0 end) as nuNHSSH,";
                sql += " sum(case when dt.manhom in ('03') and bc.mabc in ('SH') and l.phai<>'Nam' then 1 else 0 end) as nuDta,";
                sql += " 0 as nuCBkhac,0 as nubs1";
                
                sql += ",sum(case when dt.manhom in ('10') and l.phai<>'Nam' then 1 else 0 end) as nuluongy";
               
                sql += " ,sum(case when (mh.nhombc=2) and l.phai<>'Nam' then 1 else 0 end) as nuTquy,";
                sql += " sum(case when (mh.nhombc =3 or mh.nhombc =4) and l.phai<>'Nam' then 1 else 0 end) as nuNquy";

                sql += " from "+user+".llnv l inner join "+user+".hopdong hd on l.manv=hd.manv";
                sql += " inner join "+user+".bophan bp on  bp.madv=l.madv";
                sql += " left join "+user+".dmcd cd on cd.ma=l.macd";
                sql += " left join "+user+".bangcap bc on bc.mabangcap=l.td_nnghiep";
                sql += " left join "+user+".mangach mn on hd.mangach=mn.ma";
                sql += " left join "+user+".mahd mh on hd.loaihd=mh.mahd";
                sql += " left join "+user+".ctdaotao dt on l.nnghiep=dt.mactdt";
                sql += " inner join "+user+".max_lan ml on hd.manv=ml.manv";
                sql += " where  (hd.ngaynghi is null or to_timestamp(hd.ngaynghi,'yyyy-mm-dd') > to_timestamp('" + denngay + "','yyyy-mm-dd')) ";
                sql += " and to_timestamp(hd.ngaydenct,'yyyy-mm-dd')<=to_timestamp('" + denngay + "','yyyy-mm-dd') ";
                sql += " and hd.lan=ml.lan";
                sql += " group by bp.tenbp,bp.sothutu,";
                sql += " case when substr(trim(bp.mabsoft),1,1)='P' then 'I. Các phòng' ";
                sql += " when substr(trim(bp.mabsoft),1,1)='L' then 'II. Khoa lâm sàng' ";
                sql += " when substr(trim(bp.mabsoft),1,1)='C' then 'III. Cận lâm sàng'";
                sql += " when substr(trim(bp.mabsoft),1,1)='D' then 'IV. Y tế dự phòng'";
                sql += " when substr(trim(bp.mabsoft),1,1)='X' then 'V. Y tế xã'";
                sql += " when substr(trim(bp.mabsoft),1,1)='K'  then 'VI. Bộ phận khác' end";
                sql += " order by bp.sothutu";
				dsxml =mDB.get_data(sql);
                dsxml.WriteXml("..\\xml\\h_tinhhinhCCVCtheoquy.xml", XmlWriteMode.WriteSchema);
				if(dsxml.Tables[0].Rows.Count!=0)
				{
                    foreach (DataRow dr in dsxml.Tables[0].Rows)
                    {
                        int c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0, c7 = 0, c8 = 0, c9 = 0, c10 = 0, c11 = 0, c12 = 0, c13 = 0, c14 = 0, c15 = 0, c16 = 0, c17 = 0, c18 = 0, c19 = 0, c20 = 0, c21 = 0, c22 = 0
                          ,nc3 = 0, nc4 = 0, nc5 = 0, nc6 = 0, nc7 = 0, nc8 = 0, nc9 = 0, nc10 = 0, nc11 = 0, nc12 = 0, nc13 = 0, nc14 = 0, nc15 = 0, nc16 = 0, nc17 = 0, nc18 = 0, nc19 = 0, nc20 = 0, nc21 = 0, nc22 = 0 ;
                          
                        c1 = dr["tongso"].ToString().Trim() != "" ? int.Parse(dr["tongso"].ToString()) : 0;
                        c2 = dr["tongnu"].ToString().Trim() != "" ? int.Parse(dr["tongnu"].ToString()) : 0;
                        c3 = dr["gs"].ToString().Trim() != "" ? int.Parse(dr["gs"].ToString()) : 0;
                        c4 = dr["ts"].ToString().Trim() != "" ? int.Parse(dr["ts"].ToString()) : 0;
                        c5 = dr["ths"].ToString().Trim() != "" ? int.Parse(dr["ths"].ToString()) : 0;
                        c6 = dr["CKII"].ToString().Trim() != "" ? int.Parse(dr["CKII"].ToString()) : 0;
                        c7 = dr["CKI"].ToString().Trim() != "" ? int.Parse(dr["CKI"].ToString()) : 0;
                        c8 = dr["BS"].ToString().Trim() != "" ? int.Parse(dr["BS"].ToString()) : 0;
                        c9 = dr["dsdh"].ToString().Trim() != "" ? int.Parse(dr["dsdh"].ToString()) : 0;
                        c10 = dr["dhkhac"].ToString().Trim() != "" ? int.Parse(dr["dhkhac"].ToString()) : 0;
                        c11 = dr["ytdh"].ToString().Trim() != "" ? int.Parse(dr["ytdh"].ToString()) : 0;
                        c12 = dr["ysth"].ToString().Trim() != "" ? int.Parse(dr["ysth"].ToString()) : 0;
                        c13 = dr["ktv"].ToString().Trim() != "" ? int.Parse(dr["ktv"].ToString()) : 0;
                        c14 = dr["dsth"].ToString().Trim() != "" ? int.Parse(dr["dsth"].ToString()) : 0;
                        c15 = dr["ytth"].ToString().Trim() != "" ? int.Parse(dr["ytth"].ToString()) : 0;
                        c16 = dr["nhsth"].ToString().Trim() != "" ? int.Parse(dr["nhsth"].ToString()) : 0;
                        c17 = dr["thkhac"].ToString().Trim() != "" ? int.Parse(dr["thkhac"].ToString()) : 0;
                        c18 = dr["ytsh"].ToString().Trim() != "" ? int.Parse(dr["ytsh"].ToString()) : 0;
                        c19 = dr["nhssh"].ToString().Trim() != "" ? int.Parse(dr["nhssh"].ToString()) : 0;
                        c20 = dr["dta"].ToString().Trim() != "" ? int.Parse(dr["dta"].ToString()) : 0;
                        c22 = dr["luongy"].ToString().Trim()!=""? int.Parse(dr["luongy"].ToString()): 0;
                        c21 = c1 - (c3 + c4 + c5 + c6 + c7 + c8 + c9 + c10 + c11 + c12 + c13 + c14 + c15 + c16 + c17 + c18 + c19 + c20 + c22 );
                        // tinh so nu cbkhac
                        nc3 = dr["nugs"].ToString().Trim() != "" ? int.Parse(dr["nugs"].ToString()) : 0;
                        
                        nc4 = dr["nuts"].ToString().Trim() != "" ? int.Parse(dr["nuts"].ToString()) : 0;
                        nc5 = dr["nuths"].ToString().Trim() != "" ? int.Parse(dr["nuths"].ToString()) : 0;
                        nc6 = dr["nuCKII"].ToString().Trim() != "" ? int.Parse(dr["nuCKII"].ToString()) : 0;
                        nc7 = dr["nuCKI"].ToString().Trim() != "" ? int.Parse(dr["nuCKI"].ToString()) : 0;
                        nc8 = dr["nuBS"].ToString().Trim() != "" ? int.Parse(dr["nuBS"].ToString()) : 0;
                       
                        nc9 = dr["nudsdh"].ToString().Trim() != "" ? int.Parse(dr["nudsdh"].ToString()) : 0;
                        nc10 = dr["nudhkhac"].ToString().Trim() != "" ? int.Parse(dr["nudhkhac"].ToString()) : 0;
                        nc11 = dr["nuytdh"].ToString().Trim() != "" ? int.Parse(dr["nuytdh"].ToString()) : 0;
                        nc12 = dr["nuysth"].ToString().Trim() != "" ? int.Parse(dr["nuysth"].ToString()) : 0;
                        nc13 = dr["nuktv"].ToString().Trim() != "" ? int.Parse(dr["nuktv"].ToString()) : 0;
                        nc14 = dr["nudsth"].ToString().Trim() != "" ? int.Parse(dr["nudsth"].ToString()) : 0;
                        nc15 = dr["nuytth"].ToString().Trim() != "" ? int.Parse(dr["nuytth"].ToString()) : 0;
                        nc16 = dr["nunhsth"].ToString().Trim() != "" ? int.Parse(dr["nunhsth"].ToString()) : 0;
                        nc17 = dr["nuthkhac"].ToString().Trim() != "" ? int.Parse(dr["nuthkhac"].ToString()) : 0;
                        nc18 = dr["nuytsh"].ToString().Trim() != "" ? int.Parse(dr["nuytsh"].ToString()) : 0;
                        nc19 = dr["nunhssh"].ToString().Trim() != "" ? int.Parse(dr["nunhssh"].ToString()) : 0;
                        nc20 = dr["nudta"].ToString().Trim() != "" ? int.Parse(dr["nudta"].ToString()) : 0;
                        nc22 = dr["nuluongy"].ToString().Trim() != "" ? int.Parse(dr["nuluongy"].ToString()) : 0;
                        nc21 = c2 - (nc3 + nc4 + nc5 + nc6 + nc7 + nc8 + nc9 + nc10 + nc11 + nc12 + nc13 + nc14 + nc15 + nc16 + nc17 + nc18 + nc19 + nc20+ nc22);
                        dr["cbkhac"] = c21.ToString();
                        dr["nucbkhac"] = nc21.ToString();
                        
                    }
                        
					if(j==1)
					{
                        frmReport f = new frmReport(mDB, dsxml, "", "h_tinhhinhCCVCtheoquy.rpt",user_dn);
                        f.ShowDialog(this);
					}	
                    //else if(j==2)
                    //    rpt.Printer(dsxml,"bieu_tinhhinhCCVCtheoquy.rpt","",1);
                    //else
                    //    p.exp_excel(dsxml,"bieu_tinhhinhCCVCtheoquy");
				}
                if (dsxml.Tables[0].Rows.Count != 0)
                {

                }
                else
                {
                    MessageBox.Show(lan.Change_language_MessageText("Chưa có dữ liệu"),lan.Change_language_MessageText( "Thông báo"));
                }
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.ToString());
			}
		}

		private void btnXem_Click(object sender, System.EventArgs e)
		{
			if(radMH.Checked) print(1);
			if(radMI.Checked) print(2);
			if(radExcel.Checked) print(3);
			btnThoat.Focus();
		}

		private void btnThoat_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void nudQuy_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Enter)
				nudNam.Focus();
		}

		private void nudNam_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Enter)
				radMH.Focus();
		}

		private void radMH_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Enter)
				btnXem.Focus();
		}

		private void radMI_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Enter)
				btnXem.Focus();
		}

		private void radExcel_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Enter)
				btnXem.Focus();
		}
	}
}
